import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/data/entities/application/get_new_dict_all_entity.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/education/me_demand_research/me_demand_research_detail/select_theme_tree/regional_organization_tree_controller.dart';

///主题树状
class SelectThemeTreePage extends StatelessWidget {
  SelectThemeTreePage({super.key});

  final controller = Get.put(SelectThemeTreeController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        initState: (state) {
          controller.onInitData();
        },
        init: controller,
        builder: (_) {
          return Container(
            padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 10.w),
            decoration: BoxDecoration(
              color: const Color(0xFFE5E9FF),
              borderRadius: BorderRadius.circular(4.w),
            ),
            child: SingleChildScrollView(
                child: Column(
                  children: controller.treeList.map((item) {
                    return _getTreeView(item, 0);
                  }).toList(),
                )),
          );
        });
  }
  /// 部门数据每一项的显示
  /// [treeEntity] 当前节点数据
  /// [level] 所在层级
  Widget _getTreeView(GetNewDictAllEntity treeEntity, int level) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          constraints: BoxConstraints(
            minHeight: 55.w,
          ),
          child: Row(
            children: [
              // 间距
              SizedBox(width: 20.w * level),
              treeEntity.dictionaryDetails!.isNotEmpty
                  ? SizedBox(
                      width: 18.w,
                      child: SvgPicture.asset(
                        treeEntity.isExpand! ? AppImages.icon_arrow_drop : AppImages.icon_arrow_right,
                        width: 13.w,
                        height: 13.w,
                      ),
                    )
                  : SizedBox(
                      width: 18.w,
                    ),
              AppGaps.hGap10,
              Expanded(
                child: Container(
                  padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 6.w),
                  decoration: BoxDecoration(
                    color: treeEntity.isChecked ? const Color(0xff5C6DFF) : const Color(0xffffffff),
                    borderRadius: BorderRadius.circular(4.w),
                  ),
                  child: Text(
                    treeEntity.getShowName(),
                    style: TextStyle(
                      fontSize: 14.sp,
                      fontWeight: FontWeight.w500,
                      color: treeEntity.isChecked ? const Color(0xffffffff) : const Color(0xff34406D),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
        AnimatedSize(
          duration: const Duration(milliseconds: 700),
          // curve: Curves.easeInOut,
          curve: Curves.easeInOutExpo,
          child: SizedBox(
            height: treeEntity.isExpand! ? null : 0,
            child: Column(
              children: [
                ...treeEntity.dictionaryDetails!.map((item) {
                  return Container(
                    child: _getTreeView(item, level + 1),
                  );
                }),
              ],
            ),
          ),
        ),
      ],
    );
  }


}
